import { BASE_URL , URL} from "./const";
import axios from "axios";

export function request (config) {
  const server = axios.create({
    baseURL:BASE_URL,
    timeout:60000,
    method:config?.method ? config.method : "GET"
  })
  server.interceptors.request.use(con => {
    if(localStorage.getItem('token')){
      con.headers.Authorization = localStorage.getItem('token')
    }
    return con
  })
  server.interceptors.response.use(res => {
    return res.data
  },
  err => {
    return err
  })


  return server(config)
}

export function http (config) {
  const server = axios.create({
    baseURL:URL,
    timeout:60000,
    method:config?.method ? config.method : "GET"
  })
  server.interceptors.request.use(con => {
    if(localStorage.getItem('token')){
      con.headers.Authorization = localStorage.getItem('token')
    }
    return con
  })
  server.interceptors.response.use(res => {
    return res.data
  },
  err => {
    return err
  })


  return server(config)
}

// ?.  可选链操作符
